/**
 * 商品价格查询
 * @author shixc
 * @date 2019/06/04
 */
define(function () {

    var self,
        doc = document,
        app = win.app,
        layui = win.layui,
        element,
        table, END, START,
        table_where = {},
        cols = [[
            {field: 'ID', type: 'checkbox', title: '选择', fixed: 'left'}
            , {
                field: 'GWDC004', width: 80, title: '定价类型', fixed: 'left', filterDatas: app.datas_('crm_gwai810_type'),
                search: 'default', searchOpts: {type: 'select'}
            }
            , {
                field: 'GWDB003', width: 80, title: '对象类型', filterDatas: app.datas_('crm_gwcd_gwcd007'),
                search: 'default', searchOpts: {type: 'select'}
            }
            , {field: 'GWDB012', width: 80, title: '对象编号'}
            , {field: 'GWDB013', width: 80, title: '对象名称'}
            , {field: 'ACTI', width: 80, title: '审核码',filterDatas:app.datas_('check_code')}
            , {field: 'GWAM007_NAME', width: 120, title: '产品分类'}
            , {field: 'GWAM004_NAME', width: 80, title: '产品系列', search: 'default', searchOpts: {icon: true}}
            , {field: 'GWAM001', width: 80, title: '品号', search: 'default', searchOpts: {icon: true}}
            , {field: 'GWAML003', width: 80, title: '品名'}
            , {field: 'GWAML004', width: 80, title: '规格', search: 'default', searchOpts: {icon: true}}
            , {field: 'GWAM008', width: 80, title: '单位'}
            , {field: 'GWDB005', width: 80, title: '生效日期', search: 'default', searchOpts: {type: 'date'}}
            , {field: 'GWDB006', width: 80, title: '失效日期', search: 'default', searchOpts: {type: 'date'}}
            , {field: 'GWDB016', width: 80, title: '结算价'}
            , {field: 'GWDC024', width: 80, title: '活动价'}
            , {field: 'GWDC020', width: 80, title: '起订量'}
            , {field: 'GWDC021', width: 80, title: '起订金额'}
            , {field: 'GWDC001', width: 140, title: '活动编号', search: 'default',searchOpts:{icon:true}}
            , {field: 'GWDC003', width: 80, title: '活动说明'}
            , {field: 'GWDC005', width: 80, title: '促销方式', filterDatas: app.datas_('crm_gwcd_gwcd005')}
            , {field: 'GWDC022', width: 80, title: '阶梯定价否'}
        ]],
        gwai780table, company
    ;

    var Gwai810 = app.Module.extend({
        init: function () {
            self = this;
            var _searchsArr = app.cloneJSON(cols[0]);
            self._super({
                _tag: 'gwai810',
                _searchs: [{
                    id: 'gwai810', tableId: 'gwai810_table', datas: _searchsArr.pushArray([
                        {
                            field: 'GWDB012_1',
                            title: '渠道',
                            search: 'default',
                            searchOpts: {icon: true}
                        },
                        {
                            field: 'GWDB012_2',
                            title: '渠道商',
                            search: 'default',
                            searchOpts: {icon: true}
                        }
                    ])
                }],
                _loadTplsFull: [
                    {dom: 'common_open_window', tpl: 'common/_open_window'}
                ]
            }, win);
        },

        initTable: function () {
            layui.use(['table'], function () {
                table = layui.table;
                gwai780table = table.render({
                    elem: app.getByid(doc, 'gwai810_table'),
                    url: g_ctxPath + 'crm/gwai810/getListData',
                    exportsUrl: g_ctxPath + 'crm/gwai810/exportsData',
                    exportsName: '商品价格查询数据',
                    title: '商品价格信息表',
                    method: 'post',
                    id: 'gwai810_table',
                    toolbar: '#table-toolbar',
                    defaultToolbar: ['filter', 'exports_import'],
                    height: 'full',
                    cols: cols,
                    loading: true,
                    page: true,
                    where: table_where,
                    done: function (res, curr, count) {

                    }
                });

                var tipsIndex = null;

                $(doc).on('click', function () {
                    tipsIndex && layer.close(tipsIndex);
                });

            });
        },

        reloadTableCurr: function () {
            self._reloadTable({id: 'gwai810_table', where: table_where});
        },

        _ready: function () {
            this._super({
                vue: [{
                    el: '#page',
                    data: '',
                    searchId: 'gwai810',
                    methods: {
                        handleIconClick: function (field) {
                            var vue = this;
                            if (field == 'GWDB012_1') {//渠道开窗
                                self._openTplFull({
                                    tag: 'common_open_window',
                                    tagData: {
                                        config:{
                                            method:'q_gwae001',
                                            columnList:[
                                                {label:'销售渠道编号',prop:'GWAE001', width: 150},
                                                {label:'说明',prop:'GWAEL003', width: 150},
                                                {label:'助记码',prop:'GWAEL004', width: 150}
                                            ]
                                        },
                                        cb: function (data) {
                                            vue.isearch.fields.GWDB012_1 = data.GWAE001;
                                        }
                                    },
                                    index: 0,
                                    openOpts: {
                                        title: '选择渠道',
                                        area: ['600px', '430px']
                                    }
                                });
                            } else if (field == 'GWDB012_2') {//客户开窗
                                self._openTplFull({
                                    tag:'common_open_window',
                                    tagData:{
                                        config:{
                                            method:'q_gwak001',
                                            columnList:[
                                                {label:'客户编号',prop:'GWAK001', width: 150},
                                                {label:'客户简称',prop:'GWAKL003', width: 150},
                                                {label:'客户全称',prop:'GWAKL004', width: 150}
                                            ]
                                        },
                                        cb: function (data) {
                                            vue.isearch.fields.GWDB012_2 = data.GWAK001;
                                        }
                                    },
                                    index: 0,
                                    openOpts: {
                                        title: '选择客户',
                                        area: ['600px', '430px']
                                    }
                                });
                            } else if (field == 'GWAM004_NAME') {
                                self._openTplFull({
                                    tag: 'common_open_window',
                                    tagData: {
                                        config:{
                                            method:'q_gwao001',
                                            columnList:[
                                                {label:'产品系列编号',prop:'GWAO001', width: 150},
                                                {label:'说明',prop:'GWAOL003', width: 150},
                                                {label:'助记码',prop:'GWAOL004', width: 150},
                                            ]
                                        },
                                        cb: function (data) {
                                            vue.isearch.fields.GWAM004_NAME = data.GWAOL003;
                                            table_where.GWAM004 = data.GWAO001;
                                        }
                                    },
                                    index: 0,
                                    openOpts: {
                                        title: '选择产品系列',
                                        area: ['600px', '430px']
                                    }
                                });
                            } else if (field == 'GWAM001' || field == 'GWAML004') {
                                self._openTplFull({
                                    tag: 'common_open_window',
                                    tagData: {
                                        config:{
                                            method:'q_gwam001',
                                            columnList:[
                                                {label:'设备编号',prop:'GWAM001', width: 150},
                                                {label:'品名',prop:'GWAML003', width: 150},
                                                {label:'规格',prop:'GWAML004', width: 150}
                                            ]
                                        },
                                        cb: function (data) {
                                            vue.isearch.fields.GWAM001 = data.GWAM001;
                                            vue.isearch.fields.GWAML004 = data.GWAML004;
                                        }
                                    },
                                    index: 0,
                                    openOpts: {
                                        title: '选择产品',
                                        area: ['600px', '430px']
                                    }
                                });
                            }else if(field == 'GWDC001'){
                                self._openTplFull({
                                    tag: 'common_open_window',
                                    tagData: {
                                        config: {
                                            columnList: [{label: '活动编号', prop: 'GWDC001', width: '150'},
                                                {label: '活动说明', prop: 'GWDC003', width: '150'},
                                                {label: '日期', prop: 'GWDC008', width: '150'},
                                                {label: '状态码', prop: 'GWDCACTI_NAME', width: '150'}
                                            ],
                                            url: 'crm/gwdc003/getGwdc001Data'
                                        },
                                        cb: function (data) {
                                            vue.isearch.fields.GWDC001 = data.GWDC001;
                                        }
                                    },
                                    index: 0,
                                    openOpts: {
                                        title: '选择活动编号',
                                        area: ['600px', '470px']
                                    }
                                });
                            }
                        }
                    },
                    watch: {
                        'isearch.fields.GWAM004_NAME': function (val) {
                            if (val == '' || val == null) {
                                table_where.GWAM004 = '';
                            }
                        }
                    }
                }]
            });
            self.initTable();
        },
        _lazy: function () {
            this._super();
            layui.use(['table'], function () {
                element = layui.element;
            });
        }
    });

    return new Gwai810();

});
